<template>
  <div>
    <el-dialog :visible.sync="dialog" :before-close="handleCancel" title="选择教室" width="800px">
      <div v-loading="loading">
        <div class="selectClass-box">
          <div class="selectClass-left">
            <el-button type="primary" @click="goClassRoom">新建教室</el-button>
            <el-button type="text" @click="reloadClick">刷新</el-button>
          </div>
          <div class="selectClass-right">
            <el-input v-model="keyWord" placeholder="请输入教室名称" style="width:200px;" />
            <el-button>搜索</el-button>
          </div>
        </div>
        <div class="table-box">
          <el-table
            :data="classRoomList"
            class="textRadio"
            style="width: 100%;"
            @row-click="clickRow"
          >
            <el-table-column width="50" align="center">
              <template slot-scope="scope">
                <el-radio :label="scope.row.id" v-model="belongCourseRadio" />
              </template>
            </el-table-column>
            <el-table-column prop="classRoomName" label="课程名称" />
            <el-table-column prop="maxPerson" label="可容纳人数" align="center" />
            <el-table-column prop="campusNum" label="校区名称" align="right" />
          </el-table>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleCancel">取 消</el-button>
        <el-button type="primary" @click="handleConfirm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    dialog: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      loading: false,
      keyWord: '',
      belongCourseRadio: '',
      belongCourseName: '',
      classRoomList: [
        {
          id: '122',
          classRoomName: '快速提升教室',
          maxPerson: '100',
          campusNum: '东校区'
        },
        {
          id: '125',
          classRoomName: '基础提升教室',
          maxPerson: '100',
          campusNum: '校本部'
        }
      ]
    }
  },
  methods: {
    reloadClick() {
      this.loading = true
      setTimeout(() => {
        this.loading = false
      }, 1000)
    },
    clickRow(row) {
      this.belongCourseRadio = row.id
      this.belongCourseName = row.classRoomName
    },
    handleCancel() {
      this.$emit('cancelClick')
    },
    handleConfirm() {
      this.$emit('confirmClick', {
        'id': this.belongCourseRadio,
        'name': this.belongCourseName
      })
    },
    goClassRoom() {
      this.$router.push({ name: 'Createclassroom' })
    }
  }
}
</script>

<style lang="scss" scoped>
.selectClass-box {
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  .selectClass-left {
  }
  .selectClass-right {
    float: right;
  }
}
.textRadio {
  /deep/.el-radio__label {
    display: none;
  }
}
.table-box {
  max-height: 500px;
  overflow: auto;
}
</style>
